<?php 
include_once '../Utilities/connect.php';
/* @var $conn type */
$conn=  getConnect();
  mysql_set_charset('utf8',$conn);
function getNameCategory($categoryID)
{
    $conn=  getConnect();
   
    $arr=array();
    $arr_category=array();
    $i=0;
    $sql="select * from categories where CategoryID='$categoryID'";
    $result=  mysql_query($sql, $conn);
    if(!$result)
        die('Truy van ko hop le');
     while($row= mysql_fetch_assoc($result))
    {
         $arr=array(0=>$row['CategoryID'],1=>$row['CategoryName']);
    }
    return $arr;
    mysql_close($conn);
}
function getAllCategory()
{
    $conn=  getConnect();
    $arr=array();
    $arr_add=array();
    $sql="Select * from categories";
    $result=  mysql_query($sql, $conn);
     if(!$result)
        die('Truy van ko hop le');
     $i=0;
    while($row=  mysql_fetch_assoc($result))
    {
        $arr=array('ID'=>$row['CategoryID'],'CategoryName'=>$row['CategoryName'],'ParentID'=>$row['ParentID'],'isVisable'=>$row['isVisable']);
        $arr_add[$i]=$arr;
        $i+=1;
    }
    return $arr_add;
    mysql_close($conn);
}

function InsertCate($name, $parentid, $isVisable)
{
    
        $conn=  getConnect();
	$sql= "insert into categories(CategoryName, ParentID, isVisable ) values('$name','$parentid','$isVisable')";
        $result=  mysql_query($sql,$conn);
        return $result;
        mysql_close($conn);
}
function DeleteCate($CategoryID)
{
         $conn=  getConnect();
         if(!$conn)
             die("Error connect");
	$sql= "delete from categories where CategoryID='$CategoryID'";    
        $result=  mysql_query($sql,$conn);
        if(!$result)
            die("error query");
        return $result;
        mysql_close($conn);
}
function UpdateCate($name, $parentid, $isVisable,$categoryid)
{
     $conn=  getConnect();
	$sql= "update categories set CategoryName='$name',ParentID='$parentid', isVisable='$isVisable' where CategoryID='$categoryid'";
        $result=  mysql_query($sql,$conn);
        return $result;
        mysql_close($conn);
}
function getCategoryForMenu($parentId)
{
 	$sql ="select * from categories where isVisable=1 and ParentID= '$parentId'";
	mysql_query($sql, getConnect());
	$arr=array();
		while ($category = mysql_fetch_array($rl))
		{
		 	$arr[]=$category;
		}
		return $arr;	
	
}
?>